package com.sun.showcase.controller.mall;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

import com.sun.showcase.biz.mall.service.ShoppingCartService;
import com.sun.showcase.pojo.DataGrid;
import com.sun.showcase.pojo.Result;
import com.sun.showcase.client.domain.mall.ShoppingCart;
import com.sun.showcase.client.query.mall.ShoppingCartQuery;

@Controller
@RequestMapping(value="/mall/shoppingCart") 
public class ShoppingCartController{
	
	@Autowired
	private ShoppingCartService shoppingCartService;
	
	private Result result = new Result();
	/**
	 * 跳转到ShoppingCart管理页面
	 * 
	 * @return
	 */
	@RequestMapping(value="goShoppingCart")
	public String goShoppingCart() {
		return "mall/shoppingCart";
	}
	/**
	 * 跳转到ShoppingCart新增页面
	 * 
	 * @return
	 */
	@RequestMapping(value="handleShoppingCart")
	public String handleShoppingCart(@RequestParam(value="id",required=false) Long id ,ModelMap map) {
		return "mall/shoppingCart_rowEdit";
	}

	/**
	 * 跳转到查看desc页面
	 * 
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="showDesc")
	public ShoppingCart showDesc(ShoppingCartQuery shoppingCartQuery) {
		return shoppingCartService.get(shoppingCartQuery);
	}

	/**
	 * 获得分页数据表格
	 */
	@ResponseBody
	@RequestMapping(value = "/datagrid")
	public DataGrid datagrid(ShoppingCartQuery shoppingCartQuery) {
		return shoppingCartService.datagrid(shoppingCartQuery);
	}
	

	/**
	 * 添加一个ShoppingCart
	 */
	@ResponseBody
	@RequestMapping(value="add")
	public Result add(ShoppingCartQuery shoppingCartQuery) {
		shoppingCartService.add(shoppingCartQuery);
		result.setSuccess(true);
		result.setMsg("添加成功！");
		return result;
	}

	/**
	 * 编辑ShoppingCart
	 */
	@ResponseBody
	@RequestMapping(value="edit")
	public Result edit(ShoppingCartQuery shoppingCartQuery) {
		shoppingCartService.update(shoppingCartQuery);
		result.setSuccess(true);
		result.setMsg("编辑成功！");
		return result;
	}

	/**
	 * 物理删除ShoppingCart
	 */
	@ResponseBody
	@RequestMapping(value="delete")
	public Result delete(ShoppingCartQuery shoppingCartQuery) {
		shoppingCartService.delete(shoppingCartQuery.getIds());
		result.setSuccess(true);
		result.setMsg("删除成功！");
		return result;
	}
	
	/**
	 * 逻辑删除ShoppingCart
	 */
	@ResponseBody
	@RequestMapping(value="deletePt")
	public Result deletePt(ShoppingCartQuery shoppingCartQuery) {
		shoppingCartService.deletePt(shoppingCartQuery.getIds());
		result.setSuccess(true);
		result.setMsg("删除成功！");
		return result;
	}
	/**
	 * 全部数据ShoppingCart
	 */
	@ResponseBody
	@RequestMapping(value="listAll")
	public Result listAll(ShoppingCartQuery shoppingCartQuery) {
		List<ShoppingCartQuery> list = shoppingCartService.listAll(shoppingCartQuery);
		result.setSuccess(true);
		result.setMsg("成功！");
		result.setData(list);
		return result;
	}
}
